<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
</head>
<style>
    .timeLine {
        width: 100%;
        display: -webkit-flex;
        display: flex;
        flex-direction: row;
    }

    .timeLineImg {
        width: 20%;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .timeLineLeft {
        height: 100%;
        width: 2px;
        border-left: 1px solid #B0B0B0;
    }

    .timeLineInfo {
        width: 80%;
    }

    .timeLineInfoTitle {
        font-size: 20px;
        color: #3f51b5;
    }

    .timeLineInfoIntroduce {
        font-size: 16px;
        color: #0062cc;
    }

    .timeLineInfoTime {
        font-size: 12px;
        color: #CA92C4;
    }

    .scoll {
        overflow: auto;
        margin-top: 65px;
    }

    .aui-list .aui-list-item:after {
        width: 100%;
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: auto;
        right: auto;
        bottom: 0;
        left: 0;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-list:before {
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: 0;
        left: 0;
        right: auto;
        bottom: auto;
        width: 100%;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-card-list-header {
        color: #212121;
        font-size: 22px;
        font-weight: 600;
    }

    #addEmpBtn:before {
        content: url(../image/pn.png);
    }

    #addMrlBtn:before {
        content: url(../image/pn.png);
    }
</style>

<body>
    <div style="height:114px;width:100%;position: fixed;top: 0px;bottom: auto;table-layout: fixed;z-index: 10;">
        <!-- <header class="aui-bar aui-bar-nav ui-selectee">维修单详情</header> -->
        <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
            <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title" id="title">
                维修单详情
            </div>
        </header>
        <div class="aui-tab aui-border-b" id="tab"  style="margin-top:50px;">
            <div class="aui-tab-item aui-active">设备故障</div>
            <div class="aui-tab-item">处理意见</div>
            <div class="aui-tab-item">工作量</div>
            <div class="aui-tab-item">更换备件</div>
        </div>
    </div>
    <div class="aui-padded-5 " id="tab1-con" style="margin-top: 90px;">
        <div id="tab1-con1">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list ui-selectee">
                        <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                            <ul class="aui-list aui-form-list" style="content: none;line-height: 3.5rem;font-size: 17px;">
                                <li class="aui-list-item" style="content: none;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">设备编码</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipCode" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">设备名称</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipName" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">设备型号</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipModel" value="" />
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                        <ul class="aui-list aui-form-list" style="content: none;line-height: 3.5rem;font-size: 17px;">
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label ui-selectee">故障描述</div>
                                    <div class="aui-list-item-input ui-selectee">
                                        <input type="text" readonly id="description" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">提报人</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="createId" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">故障提报时间</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="faultdate" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label">故障等级</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="faultLevel" value="" />
                                    </div>
                                </div>
                            </li>



                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- 处理意见 -->
        <div class="aui-hide" id="tab1-con2">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list ui-selectee">
                        <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                            <ul class="aui-list aui-form-list" style="content: none;">
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label" style="width: 45%;">开始时间</div>
                                        <div class="aui-list-item-input">
                                            <input readonly class="form-control" type="text" id="beginDate" placeholder="请选择">
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label" style="width: 45%;">结束时间</div>
                                        <div class="aui-list-item-input">
                                            <input readonly class="form-control" type="text" id="endDate" placeholder="请选择">
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">实际工时(分)</div>
                                        <div class="aui-list-item-input ui-selectee"> <input class="form-control"  type="text" id="actualtime">
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                        <ul class="aui-list aui-form-list" style="content: none;">
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修描述</div>
                                    <div class="aui-list-item-input">
                                        <input class="form-control" type="text" id="repairDescription">
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label">班组</div>
                                    <div class="aui-list-item-input">
                                        <select id="teamGid" placeholder="请选择">
                                  </select>
                                    </div>
                                </div>
                            </li>

                        </ul>
                    </div>
                </div>
            </div>
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                        <ul class="aui-list aui-form-list" style="content: none;">
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label ui-selectee">状态</div>
                                    <div class="aui-list-item-input ui-selectee">
                                        <select id="status" placeholder="请选择">
                                    </select>
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">原因分析</div>
                                    <div class="aui-list-item-input">
                                        <input class="form-control" type="text" id="causeAnalysis">
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">故障类别</div>
                                    <div class="aui-list-item-input">
                                        <select id="faultClass" placeholder="请选择">
                                    </select>
                                    </div>
                                </div>
                            </li>
                            <!-- <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修类别</div>
                                    <div class="aui-list-item-input">
                                        <select id="inspectionClass" placeholder="请选择">
                                    </select>
                                    </div>
                                </div>
                            </li> -->
                            <!-- <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label">维修单号</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="inspectionCode" value="" />
                                    </div>
                                </div>
                            </li> -->
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- 工作量 -->
        <div class="aui-hide" id="tab1-con3">
            <div class="aui-btn aui-btn-block" style="background-color:#ffffff;" onclick="goSelectEmp()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 0.7rem" id="addEmpBtn">增加人员</i>
            </div>
            <ul class="ui-selectee" id="tbodyHtml" style="margin-bottom:2.25rem;">

            </ul>
        </div>
        <!-- 更换备件 -->
        <div class="aui-hide" id="tab1-con4">
            <div class="aui-btn aui-btn-block" style="background-color:#ffffff;" onclick="goSelectMrl()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 0.7rem" id="addEmpBtn">增加备件</i>
            </div>
            <ul class="ui-selectee" id="tbodyMrlHtml" style="margin-bottom:2.25rem;">

            </ul>
        </div>


    </div>
    <footer class="aui-bar aui-bar-tab ui-selectee" style="color: #f5f5f5;">
        <div class="aui-bar aui-bar-btn aui-bar-btn-full ui-selectee" style="min-height: 2.8rem;font-size: 1.0rem;">
            <div class="aui-bar-btn-item ui-selectee" style="border-color: #f5f5f5;background-color: #285688;" onclick="submit()">提交</div>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script>
//返回按钮
function closeWin() {
    api.closeWin({});
}
    apiready = function() {
        api.parseTapmode();


        //开始时间选择
        new Jdate({
            el: '#beginDate',
            format: 'YYYY-MM-DD hh:mm:ss',
            beginYear: 2000,
            endYear: 2100
        });
        //结束时间选择
        new Jdate({
            el: '#endDate',
            format: 'YYYY-MM-DD hh:mm:ss',
            beginYear: 2000,
            endYear: 2100
        });

        //查询班组下拉框
        doSearchTeamGid();
        //查询状态下拉框
        // doSearchMdparaconfig("emEquipmentFaultStatus", "status");
        // //查询故障类别下拉框
        // doSearchMdparaconfig("emEquipmentFaultClass", "faultClass");
        //
        // getEmequipmentfaultDataInfo(api.pageParam.sysid,"1"); //获取设备故障tab页信息
        // getEmequipmentfaultDataInfo(api.pageParam.sysid,"2");
        // getEmPlanEmpDataList(api.pageParam.sysid);
        // getEmPlanBJDataList(api.pageParam.sysid);
    }

    var tab = new auiTab({
        element: document.getElementById("tab"),

    }, function(ret) {
        if (ret) {
            //定义获取对象的所有兄弟节点的函数，
            function siblings(elm) {
                var a = [];
                var p = elm.parentNode.children;
                for (var i = 0; i < p.length; i++) {
                    if (p[i] !== elm) a.push(p[i]);
                }
                return a;
            }
            var index = ret.index;
            var activeC = document.getElementById("tab1-con" + index);
            activeC.className = "";
            for (var i = 0; i < siblings(activeC).length; i++) {
                siblings(activeC)[i].className = "aui-hide";
            }

            // if ("1" == index) { //tab-设备故障
            //     getEmequipmentfaultDataInfo(api.pageParam.sysid,"1");
            // }
            // if ("2" == index) { //tab-处理意见
            //     getEmequipmentfaultDataInfo(api.pageParam.sysid,"2");
            // }
            // if ("3" == index) { //tab-工作量
            //     //获取计划关联人员信息
            //     getEmPlanEmpDataList(api.pageParam.sysid);
            // }
            //
            // if ("4" == index) { //tab-更换备件
            //     //获取计划关联备件信息
            //     getEmPlanBJDataList(api.pageParam.sysid);
            // }
        }
    });

    //获取计划关联人员信息
    function getEmPlanEmpDataList(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getemPlanEmpDataList";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-title ui-selectee' name='empName' title='" + list[i].empName + "'>" + list[i].empName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' name='empCode'>" + list[i].empCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].groupName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='actualtime' οnkeyup='value=value.replace(/[^\d]/g,'')' ";
                        html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' value='" + list[i].actualtime + "'></div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee'></div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee delEmp' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    //console.log(html);
                    //console.log($api.byId("tbodyHtml"));
                    $api.html($api.byId("tbodyHtml"), html);
                    //console.log($("#tbodyHtml").html());

                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //获取计划关联备件信息
    function getEmPlanBJDataList(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmPlanBJDataList";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-title ui-selectee' name='mtlName'>" + list[i].mtlName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>备件编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' name='mtlCode'>" + list[i].mtlCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'><input type='number'  name='qty' οnkeyup='value=value.replace(/[^d]/g,' ')' ";
                        html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' ";
                        html += "value='" + list[i].qty + "'></div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee'></div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee delMrl' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    $api.html($api.byId("tbodyMrlHtml"), html);

                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyMrlHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //获取信息
    function getEmequipmentfaultDataInfo(sysid, tab) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmequipmentfaultDataInfo";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            async:false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var entity = eval(myobj.entity);
                    if (tab == "1") { //设备故障123
                        $("#equipCode").val(entity.equipCode);
                        $("#equipName").val(entity.equipName);
                        $("#equipModel").val(entity.equipModel);
                        $("#description").val(entity.description);
                        $("#createId").val(entity.createId);
                        $("#faultdate").val(entity.faultdate);
                        $("#faultLevel").val(entity.faultLevel);
                    }else if(tab == "2"){
                      $("#beginDate").val(entity.beginDate);
                      $("#endDate").val(entity.endDate);
                      $("#actualtime").val(entity.actualtime);
                      $("#repairDescription").val(entity.repairDescription);
                      $("#teamGid").find("option:contains('" + entity.teamGid + "')").attr("selected", true);
                      //console.log(entity.status);
                      $("#status").find("option:contains('" + entity.status + "')").attr("selected", true);
                      $("#causeAnalysis").val(entity.causeAnalysis);
                      //console.log(entity.faultClass);
                      $("#faultClass").find("option:contains('" + entity.faultClass + "')").attr("selected", true);
                    }

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选择维修人员
    function goSelectEmp() {
        api.openWin({
            name: 'mdEmployeeSelect',
            url: 'mdEmployeeSelect.html',
            pageParam: {
                name: "emequipmentfaltRepaire"
            }
        });
    }

    //人员选择后回调函数
    function setEmployeeList(dataList) {
        var list = dataList; //JSON.parse(dataList);
        var html = "";
        for (i in list) {
            html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-title ui-selectee' name='empName'>" + list[i].name + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee' name='empCode'>" + list[i].code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].teamName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>";
            html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='actualtime'  οnkeyup='value=value.replace(/[^\d]/g,'')' ";
            html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' value='" + 0 + "'></div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee'></div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee delEmp' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
            html += "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.append($api.byId("tbodyHtml"), html);

    }

    //删除人员
    $(document).on('click', '.delEmp', function() {
        var othis = this;
        api.confirm({
            title: '删除',
            msg: '确认删除该人员信息？',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                $(othis).parent().parent().parent().parent().parent().parent().remove();
            } else {}
        });


    })

    //选择备件
    function goSelectMrl() {
        api.openWin({
            name: 'mdMrlSelect',
            url: 'mdMrlSelect.html',
            pageParam: {
                name: "emequipmentfaltRepaire"
            }
        });
    }

    //备件选择后回调函数
    function setMrlList(dataList) {
        var list = dataList; //JSON.parse(dataList);
        var html = "";
        for (i in list) {
            html += "<li class='sortable ui-selectee ui-sortable parent' name='litr'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-title ui-selectee' name='mtlName'>" + list[i].name + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>备件编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee'name='mtlCode'>" + list[i].code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量</div>";
            html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='qty'  οnkeyup='value=value.replace(/[^d]/g,' ')' ";
            html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' ";
            html += "value='0'></div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee'></div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee delMrl' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
            html += "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";

        }
        $api.append($api.byId("tbodyMrlHtml"), html);

    }

    //删除备件
    $(document).on('click', '.delMrl', function() {
        var othis = this;
        api.confirm({
            title: '删除',
            msg: '确认删除该备件信息？',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                $(othis).parent().parent().parent().parent().parent().parent().remove();
            } else {}
        });


    })

    //班组下拉框
    function doSearchTeamGid() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                tablename: "md_labour_group",
                column_name: "group_name",
                column_value: "sysid",
                condition: " is_delete=0 ",
                un:un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            async:false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("teamGid"), html);
            }
            //查询状态下拉框
            doSearchMdparaconfig("emEquipmentFaultStatus", "status");

        });
    }
    //业务参数下拉框
    function doSearchMdparaconfig(paracls, idH) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdparaconfig";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                paracls: paracls,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            async:false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId(idH), html);
            }
            //查询故障类别下拉框
            doSearchMdparaconfig2("emEquipmentFaultClass", "faultClass");

        });
    }
    //业务参数下拉框
    function doSearchMdparaconfig2(paracls, idH) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdparaconfig";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                paracls: paracls,
                un:un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            async:false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId(idH), html);
            }
            getEmequipmentfaultDataInfo(api.pageParam.sysid,"1"); //获取设备故障tab页信息
            getEmequipmentfaultDataInfo(api.pageParam.sysid,"2");
            getEmPlanEmpDataList(api.pageParam.sysid);
            getEmPlanBJDataList(api.pageParam.sysid);
        });
    }

    //提交
    function submit() {
        //设备故障主键
        var sysid = api.pageParam.sysid;
        //开始时间
        var beginDate = $("#beginDate").val();
        //结束时间
        var endDate = $("#endDate").val();
        //实际工时
        var actualtime = $("#actualtime").val();
        //维修描述
        var repairDescription = $("#repairDescription").val();
        //班组
        var teamGid = $("#teamGid").val();
        //维修状态
        var status = $("#status").val();
        //原因分析
        var causeAnalysis = $("#causeAnalysis").val();
        //故障类别
        var faultClass = $("#faultClass").val();
        //检修类别
        //var inspectionClass = $("#inspectionClass").val();
        //维修单号
        //var inspectionCode = $("#inspectionCode").val();
        //计划关联人员
        var listEmp = [];
        $("ul[id=tbodyHtml] li[name=litr]").each(function(index) {
            var empName = document.getElementsByName("empName")[index].innerText;
            var empCode = document.getElementsByName("empCode")[index].innerText;
            var actualtime = document.getElementsByName("actualtime")[index].value;
            var mo = {
                planGid: sysid,
                planClass: '2', //故障维修
                empName: empName,
                empCode: empCode,
                actualtime: actualtime
            }
            //只有实际工时大于0 才提交
            if(parseFloat(actualtime)>0){
              listEmp.push(mo);
            }

        })
        //计划关联备件
        var listBj = [];
        $("ul[id=tbodyMrlHtml] li[name=litr]").each(function(index) {
            var mtlName = document.getElementsByName("mtlName")[index].innerText;
            var mtlCode = document.getElementsByName("mtlCode")[index].innerText;
            var qty = document.getElementsByName("qty")[index].value;
            var mo = {
                planGid: sysid,
                planClass: '2', //故障维修
                mtlName: mtlName,
                mtlCode: mtlCode,
                qty: qty
            }
            //只有数量大于0 才提交
            if(parseFloat(qty)>0){
              listBj.push(mo);
            }

        })
        //console.log(JSON.stringify(listEmp));
        //console.log(JSON.stringify(listBj));
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un'); //登录用户
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/emRepaireSave";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un, //登录用户
                sysid: sysid, //设备故障主键
                beginDate: beginDate, //开始时间
                endDate: endDate, //结束时间
                actualtime: actualtime, //实际工时
                repairDescription: repairDescription, //维修描述
                teamGid: teamGid, //班组
                status: status, //维修状态
                causeAnalysis: causeAnalysis, //原因分析
                faultClass: faultClass, //故障类别
                //inspectionClass: inspectionClass, //检修类别
                //inspectionCode: inspectionCode, //维修单号
                listEmp: listEmp, //JSON.stringify(listEmp),
                listBj: listBj //JSON.stringify(listBj)
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    api.openWin({
                        name: "emequipmentfaultRepaireList",
                        url: "emequipmentfaultRepaireList" + '.html',
                    });

                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });



    }
</script>

</html>
